/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Phan1.LietKe.PPSinh;

/**
 *
 * @author Giaotk
 */
public class LietKeTapConK {
    
    public LietKeTapConK(int n,int k){
        if (k>n) {
            System.out.println("Nhap sai du lieu, n phai lon hon = k");
            return;
        }
        
        int l = k-1;
        int[]x = new int[100];
        StringBuilder result = new StringBuilder();
        
        for (int i = 0; i < n; i++) {
            x[i] = i+1;
        }
        
        while(l>-1){
            for (int i = 0; i < k; i++) {
                result.append(x[i]);
            }
            result.append("\n");
            
            l=k-1;
            while(l>-1 && x[l]==n-k+1+l){
                l--;
            }
            if (l>-1) {
                x[l]++;
                for (int i = l; i < k; i++) {
                    x[i+1] = x[i]+1;
                }
            }
            
        }
        
        System.out.println(result);
    }
}
